#!/usr/bin/python3
# 数据封装：用两个代码实现数据合法
# 针对age设置20 >= age >= 1
class Dog:
    def __init__(self,name,age,gender):
        self.name = name
        self.age = age
        self.gender = gender
    @property #数据封装二：获取数据，返回外部不能获取的私有数据即__age
    def age(self):
         return self.__age
    @age.setter  #数据封装一；设置数据
    def age(self,age):
        if 20 >= age >= 1:
            self.__age = age #__age私有数据，私有数据外部不可获取
        else:
            self.__age = 1

    def eat(self):
        print(f'{self.age}岁的{self.name}正在吃东西....')
    def sleep(self):
        print(f'{self.age}岁的{self.name}正在睡觉....')
    def bark(self):
        print(f'{self.gender}的{self.age}岁的{self.name}正在乱叫....')
if __name__ == '__main__':
    dog1 = Dog("哮天犬",150,"雄性")
    dog1.eat()
    dog1.sleep()
    dog1.bark()
    print("_"*40)
    dog2 = Dog("旺财",10,"雌性")
    dog2.eat()
    dog2.sleep()
    dog2.bark()
    print(dir(dog2))
# isinstance(对象，类型)用法：
if __name__ == '__main__':
    num = '10'
    result = isinstance(num,int)
    print(result)

    num_list = [1,2,3,4,5]
    result = isinstance(num_list,list)
    print(result)

    num_tuple = (1, 2, 3, 4, 5)
    result = isinstance(num_tuple, list)
    print(result)


    print('____'*40)
# dir方法：
if __name__ == '__main__':
    list = [1,2]
    print(dir(list))
    print('____' * 40)
# student类
# 年龄1-120
class Student:
    def __init__(self,name,age,gender):
        self.name = name
        self.age = age
        self.gender = gender
    @property
    def age(self):
        return self.__age

    @age.setter
    def age(self,age):
        if 120 >= age >= 1:
            self.__age = age
        else:
            self.__age = 18
    @property
    def gender(self):
        return self.__gender
    @gender.setter
    def gender(self,gender):
        if gender =="男" or gender =="女":
            self.__gender =gender
        else:
            self.__gender = "未知"
    @property
    def name(self):
        return self.__name
    @name.setter
    def name(self,name):
        if isinstance(name,str) and name not in ["习大大","彭妈妈"]:
            self.__name = name
        else:
            self.__name = "无名"

    def introduce(self):
        print(f'大家好，我叫{self.name},今年{self.age}了,{self.gender}')
if __name__ == '__main__':
    student1 = Student("张三",18,"男")
    student1.introduce()

    student2 =Student("彭妈妈",-8,'妖')
    student2.introduce()

